<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Pay</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
            <legend>码支付配置</legend>
        </fieldset>
        <form class="layui-form layui-form-pane" action="" lay-filter="example">
            <input type="text" name="id" style="display: none;">
            <div class="layui-form-item">
                <label class="layui-form-label">码支付ID</label>
                <div class="layui-input-block">
                    <input type="text" name="codepayid" autocomplete="off" placeholder="请输入" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">通信密钥</label>
                <div class="layui-input-block">
                    <input type="email" name="pkey" autocomplete="off" placeholder="请输入" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">token</label>
                <div class="layui-input-block">
                    <input type="text" name="token" autocomplete="off" placeholder="请输入" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="pay_update">修改</button>
            </div>
        </form>
    </div>
</div>
<script src="/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use('form', function () {
        var $ = layui.jquery
            ,form = layui.form
            ,layer = layui.layer;
        $.ajax({url: "/getPayConfig",type: "GET",
            headers: {"token":localStorage.getItem("token")},
            async: false,cache: false,
            success: function (data) {
                form.val('example',data);
                form.render();//重新渲染页面
            },error: function (e) {layer.msg("请求错误！");}
        });
        //监听提交1
        form.on('submit(pay_update)', function (dataa) {
            var data = dataa.field
            $.ajax({url: "/UpdatePayConfig",
                data: "token="+data.token+"&codepayid="+data.codepayid+"&pkey="+data.pkey,
                type: "POST",headers: {"token":localStorage.getItem("token")},
                async: false,cache: false,
                success: function (datas) {
                    if(datas==0){
                        layer.msg("修改成功！")
                    }else {
                        layer.msg("修改失败！")
                    }
                },error: function (e) {layer.msg("请求错误！");}
            });
            return false;
        });
    });
</script>
</body>
</html>